package cn.ssm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import cn.ssm.pojo.Hall;
import cn.ssm.service.HallService;

/**
 * 
 * 影厅控制类
 * @author aihui
 * abc
 */
@Controller
@RequestMapping("/hall")
public class HallController {
	@Autowired
	HallService hallService;
	
	//查询全部影厅
	@RequestMapping("/getHallList")
	@ResponseBody
	public Object getHallList(){
		Map<String,Object> map = new HashMap<String,Object>();
		List<Hall> list=null;
		try{
			list=hallService.getHallList();
			map.put("result", list);
			map.put("message","查询成功！");
			map.put("success", true);
		}catch(Exception e){
			map.put("message","查询失败！");
			map.put("success",false);
		}
		
		return map;
	}
	
	//添加影厅信息
	@RequestMapping("/addHall")
	@ResponseBody
	public String addHall(){
		Hall hall=new Hall();
		hall.setSeats(35);
		hall.setDescription("乱码测试");
		
		int count= hallService.addHall(hall);
		if(count>0){
			return "添加成功，影响的行数为:"+count;
		}else {
			return "添加失败";
		}
	}
	//修改影厅信息
	@RequestMapping("/updateHall")
	@ResponseBody
	public String updateHall(){
		Hall hall = new Hall();
		hall.setId(5);
		hall.setSeats(30);
		hall.setDescription("修改数据");
		
		int count = hallService.updateHall(hall);
		if(count>0){
			return "修改成功，影响的行数为:"+count;
		}else{
			return "修改失败";
		}
	}
	
	//删除影厅
	@RequestMapping("/delHall")
	@ResponseBody
	public String delHall(){
		Hall hall = new Hall();
		hall.setId(6);
		hall.setSeats(0);
		hall.setDescription("");
		
		int count = hallService.delHall(hall);
		if(count>0){
			return "删除成功，影响的行数为:"+count;
		}else{
			return "删除失败！";
		}
		
	}
}
